<template>
  <div class="mod-swfHstAprv__swfhstaprv">
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <el-form-item>
        <el-button @click="state.getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="state.exportHandle()">{{ $t("export") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="state.hasPermission('swfHstAprv:swfhstaprv:save')" type="primary" @click="addOrUpdateHandle()">{{ $t("add") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="state.hasPermission('swfHstAprv:swfhstaprv:delete')" type="danger" @click="state.deleteHandle()">{{ $t("deleteBatch") }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border @selection-change="state.dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="id" label="id" header-align="center" align="center"></el-table-column>
      <el-table-column prop="procInstId" label="流程实例id" header-align="center" align="center"></el-table-column>
      <el-table-column prop="applId" label="申请单id" header-align="center" align="center"></el-table-column>
      <el-table-column prop="applType" label="业务申请单类型" header-align="center" align="center"></el-table-column>
      <el-table-column prop="dealDate" label="申请提交时间/审批时间" header-align="center" align="center"></el-table-column>
      <el-table-column prop="phaseName" label="审批段名称" header-align="center" align="center"></el-table-column>
      <el-table-column prop="dealUserId" label="提交人id/审批人id" header-align="center" align="center"></el-table-column>
      <el-table-column prop="dealUser" label="操作人" header-align="center" align="center"></el-table-column>
      <el-table-column prop="dealType" label="工作流操作区分 1:提交申请 2:撤销申请 3：审批(同意) 4:审批(拒绝) 5:审批(退回）6：终止 7:通过后撤销" header-align="center" align="center"></el-table-column>
      <el-table-column prop="aprvTaskId" label="审批任务id" header-align="center" align="center"></el-table-column>
      <el-table-column prop="aprvResult" label="审批结果 1：同意 2：拒绝 3：退回" header-align="center" align="center"></el-table-column>
      <el-table-column prop="aprvComment" label="审批意见" header-align="center" align="center"></el-table-column>
      <el-table-column prop="isLastAprv" label="是否为最终审 0：不是   1：是" header-align="center" align="center"></el-table-column>
      <el-table-column prop="createDate" label="创建时间" header-align="center" align="center"></el-table-column>
      <el-table-column prop="creator" label="创建者" header-align="center" align="center"></el-table-column>
      <el-table-column prop="updateDate" label="更新时间" header-align="center" align="center"></el-table-column>
      <el-table-column prop="updater" label="更新者" header-align="center" align="center"></el-table-column>
      <el-table-column prop="isDeleted" label="逻辑删除 0：未删除 1：已删除" header-align="center" align="center"></el-table-column>
      <el-table-column prop="remark" label="备注" header-align="center" align="center"></el-table-column>
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button v-if="state.hasPermission('swfHstAprv:swfhstaprv:update')" type="primary" link @click="addOrUpdateHandle(scope.row.id)">{{ $t("update") }}</el-button>
          <el-button v-if="state.hasPermission('swfHstAprv:swfhstaprv:delete')" type="primary" link @click="state.deleteHandle(scope.row.id)">{{ $t("delete") }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit" :total="state.total" layout="total, sizes, prev, pager, next, jumper" @size-change="state.pageSizeChangeHandle" @current-change="state.pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update :key="addKey" ref="addOrUpdateRef" @refreshDataList="state.getDataList"></add-or-update>
  </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import { nextTick, reactive, ref, toRefs, watch } from "vue";
import AddOrUpdate from "./swfhstaprv-add-or-update.vue";

const view = reactive({
  getDataListURL: "/swfHstAprv/swfhstaprv/page",
  getDataListIsPage: true,
  exportURL: "/swfHstAprv/swfhstaprv/export",
  deleteURL: "/swfHstAprv/swfhstaprv",
  deleteIsBatch: true,
  dataForm: {
  }
});

const state = reactive({ ...useView(view), ...toRefs(view) });


const addKey = ref(0);
const addOrUpdateRef = ref();
const addOrUpdateHandle = (id?: number) => {
  addKey.value++;
  nextTick(() => {
    addOrUpdateRef.value.init(id);
  });
};
</script>